local skel = fk.CreateSkill {
  name = "rmt__gouxian",
}

Fk:loadTranslationTable{
  ["rmt__gouxian"] = "构陷",
  [":rmt__gouxian"] = "出牌阶段限一次，你可令一名角色检索至多三张黑色牌，然后展示其手牌，若其手牌中存在点数连续的黑色牌，令其失去2点体力。",

  ["#rmt__gouxian"] = "构陷:你可令一名角色检索至多三张黑色牌",
  ["#ExtraShowCard"] = "%from 额外展示了牌 %card",

  ["$rmt__gouxian1"] = "楙苛待手足，致兄弟不睦，恐伤天家体面。",
  ["$rmt__gouxian2"] = "隶妾着翟衣僭仪制，伏惟陛下念及骨肉，免其死罪。",
}


skel:addEffect("active", {
  prompt = "#rmt__gouxian",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  interaction = function (self, player)
    return UI.Spin{from = 1, to = 3}
  end,
  target_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function (self, room, use)
    local player, to = use.from, use.tos[1]
    local choice = self.interaction.data
    if type(choice) ~= "number" or choice < 1 or choice > 3 then choice = 1 end
    local limit = #room.draw_pile + #room.discard_pile -- 防止检索不出死循环
    for i = 1, limit do
      if choice <= 0 or to.dead then break end
      local cid = room:getNCards(1)[1]
      room:moveCardTo(cid, Card.Processing, nil, fk.ReasonPut, skel.name, nil, true, player)
      room:delay(i < 8 and 400 or 100)
      if to:isAlive() and Fk:getCardById(cid).color == Card.Black then
        choice = choice - 1
        room:obtainCard(to, cid, true, fk.ReasonPrey, to, skel.name)
      else
        room:cleanProcessingArea({cid})
      end
    end
    if to.dead or to:isKongcheng() then return end
    local orig_hand = to:getCardIds("h")
    to:showCards(orig_hand)
    local cards = to:getCardIds("h")
    local extra = table.filter(cards, function(id) return not table.contains(orig_hand, id) end)
    -- 插结摸的牌要额外展示（但是不触发展示时机）
    if #extra > 0 then
      room:sendLog{
        type = "#ExtraShowCard",
        from = to.id,
        card = extra,
      }
      room:doBroadcastNotify("ShowCard", {
        from = to.id,
        cards = extra,
      })
      room:sendFootnote(extra, {
        type = "##ShowCard",
        from = to.id,
      })
    end
    if to.dead or #cards < 2 then return end
    local nums = {}
    for _, id in ipairs(cards) do
      if Fk:getCardById(id).color == Card.Black then
        local num = Fk:getCardById(id).number
        if table.insertIfNeed(nums, num) then
          if table.find(nums, function(n) return table.contains(nums, n + 1) or table.contains(nums, n - 1) end) then
            room:delay(800)
            room:doIndicate(player, {to})
            room:loseHp(to, 2, skel.name)
            break
          end
        end
      end
    end
  end,
})


return skel
